VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsRegistry"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Const objreg_SZ = (1)
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const KEY_ALL_ACCESS = &H3F
Private Const ERROR_SUCCESS = 0&
Private Const objreg_OPTION_NON_VOLATILE = 0&

Public Property Let Connection_Remote(vData As String)
    SaveSettingC "Software\keytax", "strConnectionRemote", vData, objreg_SZ
End Property
Public Property Get Connection_Remote() As String
    Connection_Remote = GetSettingC("Software\keytax", "strConnectionRemote")
End Property
Public Property Let Connection_Local(vData As String)
    SaveSettingC "Software\keytax", "strConnectionLocal", vData, objreg_SZ
End Property
Public Property Get Connection_Local() As String
    Connection_Local = GetSettingC("Software\keytax", "strConnectionLocal")
End Property
Public Sub SaveSettingC(strKeyName As String, strValueName As String, varValueSetting As Variant, lngValueType As Long)
'Purpose
'*******
'Set the value of a Registry key if it exists.
'if the registry key doesn't exist it will be created

On Error GoTo SaveSettingsCFix

'Variables
'*********
    Dim hKey As Long            'Handle to the key
    Dim lngRetVal As Long       'Result of API functions
    Dim SA As TSECURITY_ATTRIBUTES
    Dim create As Long

'Code
'****
    'Open or Create the registry key
    lngRetVal = RegCreateKeyEx(HKEY_LOCAL_MACHINE, strKeyName, 0, "", objreg_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, SA, hKey, create)
    If lngRetVal <> ERROR_SUCCESS Then
        MsgBox "An error occured while trying to set the registry key", vbExclamation
        Exit Sub
    End If

    'Set or create a registry value
    lngRetVal = RegSetValueEx(hKey, strValueName, 0, lngValueType, varValueSetting, CLng(Len(varValueSetting) + 1))

    RegCloseKey (hKey)

    Exit Sub

SaveSettingsCFix:
   MsgBox Err.Description, "clsRegistry.SaveSettingC: "

End Sub

Public Function GetSettingC(strKeyName As String, strValueName As String) As String
'Purpose
'*******
'Gets the value a certain registry key

On Error GoTo GetSettingsCFix

'Variables
'*********
    Dim lngRetVal As Long           'Result of the API functions
    Dim hKey As Long                'Handle of the opened key
    Dim szBuffer As String          'Setting of the queried value
    Dim lngBuffSize As Long

'Code
'****
    'Create the buffer
    szBuffer = Space(255)
    lngBuffSize = 255

    'Open the specified registry key
    lngRetVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE, strKeyName, 0, KEY_ALL_ACCESS, hKey)
    If lngRetVal <> ERROR_SUCCESS Then
        Exit Function
    End If

    'Read the opened registry key
    lngRetVal = RegQueryValueEx(hKey, strValueName, 0, 0, szBuffer, lngBuffSize)

    GetSettingC = Trim(Left(szBuffer, lngBuffSize - 1))

    'Close the registry key
    RegCloseKey (hKey)

    Exit Function

GetSettingsCFix:
    MsgBox Err.Description, "clsRegistry.GetSettingC: "

End Function



